package com.example.layautsventana;

import java.net.URL;


import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;

import java.net.URL;







import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;

public class VentanaPrincipal extends Activity {
 private android.widget.CheckBox chkEstado;
 private android.widget.EditText txtEstado;
 private android.widget.RadioGroup RGrupo;
 private android.widget.Button BLanzar;
 
 
 ////////////////////////////////
 
 ProgressBar progressBar;
 ImageView imageView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ventana_principal);
		progressBar = (ProgressBar) findViewById(R.id.progress);
		
		new BackgroundTask().execute("\\AsyncTask\\assets\\d.png");
	}

	  private class BackgroundTask extends AsyncTask<String, Void, String> 
	  {
		private Bitmap bmp = null;
		  
		@Override
		protected void onPreExecute()
		{
			  //mostramos el círculo de progreso
			  progressBar.setVisibility(View.VISIBLE);
		}
		
		@Override
		protected String doInBackground(String... urls) 
		{			
		    try
			{
		    	//se detiene la ejecución del hilo 3 segundos para que de tiempo a ver el progress
		    	Thread.sleep(3000);
		    	URL url = new URL(urls[0]);
		    	bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
			} catch (Exception e)
			{
				Log.e(VentanaPrincipal.class.toString(), e.getMessage());
			}
			//podemos pasar al onPostExecute un String	
		      return "";
		 }

		 @Override
		 protected void onPostExecute(String result) 
		 {
		    //la tarea en segundo plano ya ha terminado. Ocultamos el progreso.
			 progressBar.setVisibility(View.GONE);
			 
			 android.content.Intent intento=new android.content.Intent(VentanaPrincipal.this,VentanaLogin.class);
				startActivity(intento);
			 //si tenemos la imagen la mostramos
			 /*if (bmp != null)
			 {
				 Principal.this.imageView.setImageBitmap(bmp);
				 Principal.this.imageView.setVisibility(View.VISIBLE);
			 }
			 //si no, informamos del error
			 else
			 {
				 	Builder builder = new Builder(Principal.this);
					builder.setTitle(R.string.title_activity_ventana_grafica);
					builder.setIcon(android.R.drawable.ic_dialog_info);
					builder.setMessage(R.string.error_invalid_email);					
					builder.setNeutralButton(getString(R.string.txt_usuario), null);			
					AlertDialog alertDialog = builder.create();
					alertDialog.show();
				*/
		  }
		}
 /////////////////////////////
 
 
 
 /*   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_principal);
        chkEstado=(android.widget.CheckBox) findViewById(R.id.estado);
        txtEstado=(android.widget.EditText) findViewById(R.id.txtestado);
        RGrupo=(android.widget.RadioGroup) findViewById(R.id.rgrupo);
        BLanzar=(android.widget.Button) findViewById(R.id.blan);
        chkEstado.setOnCheckedChangeListener(new android.widget.CheckBox.OnCheckedChangeListener(){
        	public void onCheckedChanged(android.widget.CompoundButton cb,boolean e)
        	{
        		if(e)
        			txtEstado.setText("Casado");
        		else
        			txtEstado.setText("Soltero");
        	}
        });
        
        RGrupo.setOnCheckedChangeListener(new android.widget.RadioGroup.OnCheckedChangeListener(){
        	public void onCheckedChanged(android.widget.RadioGroup g,int id)
        	{
        		int i=g.getCheckedRadioButtonId();
        		android.widget.RadioButton r=(android.widget.RadioButton) findViewById(R.id.rgrupo);
        		txtEstado.setText("id"+r.getText());
        		txtEstado.setText("id"+i);
        	}
        });
        BLanzar.setOnClickListener(new android.view.View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				android.content.Intent intento=new android.content.Intent(Principal.this,LoginActivity.class);
				intento.putExtra("param1",txtEstado.getText().toString());
				startActivity(intento);
			}
		});
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.principal, menu);
        return true;
    }*/
    
    
}
